package com.miplus.ccrm.sms;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.miplus.ccrm.common.JDataService;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author： Yaohui
 * @Date： 2025/5/18 16:08
 * @Describe：
 */
@Service
public class OnLineUtils {

//    @Value("mrcode")
    private static final String mrCode="A";//机房号

    //系统简称
    private static final String dsc="00NDCS";// 00NDCS

//    @Resource
//    private JDataService jDataService;
    
    @Resource
    private JDataService jDataService;

    // 方法保持静态（需要加个中介）
    private static OnLineUtils instance;

    @PostConstruct
    public void init() {
        instance = this;
    }

    /**
     *
     * @param sysCode  B(业务流水号)、G(全局流水号)、S(系统内流水号)
     * @return
     */
    public static String getSeqSerialNumber(String sysCode){
        JDataService service = instance.jDataService;

        // 获取当前日期和时间
        LocalDateTime currentDateTime = LocalDateTime.now();
        String yyyyMMdd = currentDateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        if(ObjectUtils.isEmpty(sysCode)){
            return dsc+mrCode+yyyyMMdd+service.getOnlineDailySequence();
        }
        return sysCode+dsc+mrCode+yyyyMMdd+service.getOnlineDailySequence();
    }
}
